local FightBehavior = class("FightBehavior")
-- 战斗实例执行一个动作

function FightBehavior:ctor()
end

function FightBehavior:setEntity(entity)
    self._entity = entity
end

function FightBehavior:excute(battleReport) -- 定义一个接口规范
end

function FightBehavior:getName()
    return self.__cname
end

function FightBehavior:getSkillTargetEntity(target, skill)
    local FightHelper = require("gameLogic.fight.FightHelper")
    local FightConst = require("const.FightConst")
    local enemys, forEntityId = self:getTargetEntitys(skill:getConfig().attack_idx)
    assert(#enemys > 0, "not attack target by skillId=" .. skill:getId())
    local param = {}
    param.enemys = enemys
    param.amount = skill:getAmount()
    param.forEntityId = forEntityId
    local targetFunc = FightHelper["_SKILL_TARGET_" .. target]
    return targetFunc(param)
end

function FightBehavior:getSkillTargetEntityUser(target, skill, entityId)
    local FightHelper = require("gameLogic.fight.FightHelper")
    local FightConst = require("const.FightConst")
    local enemys, forEntityId = self:getTargetEntitys(skill:getConfig().attack_idx)
    local canFind = function()
        for i = 1, #enemys do
            if enemys[i]:getId() == entityId then
                return true
            end
        end
        return false
    end
    if not canFind() then
        return self:getSkillTargetEntity(target, skill)
    end
    local param = {}
    param.enemys = enemys
    param.amount = skill:getAmount()
    param.entityId = entityId
    param.forEntityId = forEntityId
    local targetFunc = FightHelper["_SKILL_TARGET_" .. target]
    return targetFunc(param)
end

function FightBehavior:getTargetEntitys(attack_idx)
    local FightConst = require("const.FightConst")
    if attack_idx == FightConst.SKILL_ATTACK_ENEMY then
        local excuter = self._entity:getExcuter()
        local enemys = self._entity:getEnemys()
        local forEntityId = 0
        local ridicule = excuter:getBuffManager():checkRidiculeBuff(self._entity)
        if ridicule then
            forEntityId = ridicule:getId()
        end
        local callEnemys = excuter:getHatredCalEntity(self._entity:getCamp())
        if #callEnemys > 0 then
            forEntityId = callEnemys[#callEnemys]:getId()
        end
        local result = {}
        for i = 1, #callEnemys do
            table.insert(result, callEnemys[i])
        end
        for i = 1, #enemys do
            table.insert(result, enemys[i])
        end
        return result, forEntityId
    else
        return self._entity:getFriends()
    end
end

return FightBehavior
